// 封装一个异步函数，检查是否已经登录
async function checkLogin() {
  // 读取cookie
  let business = cookie.get('business') ? JSON.parse(cookie.get('business')) : {}
  // console.log(business)

  // 切换到UserIndex时检查cookie中是否存在business,不存在则说明没登录
  if (Object.getOwnPropertyNames(business).length > 0) {
    // 查询数据
    let params = {
      id: business.id,
      mobile: business.mobile
    }
    // 将id、mobile发送到business/check接口
    let res = await POST({
      url: 'business/check',
      params
    })
    console.log(res)
    if (res.code === 1) {
      // 更新cookie
      cookie.set('business', JSON.stringify(res.data))
    } else {
      // 非法登录--删除cookie并跳转到登录页面
      mui.toast('非法登录')
      cookie.remove('business')
      setTimeout(() => {
        location.href = 'login.html'
      }, 2000)
    }
  } else {
    mui.toast('请先登录')
    setTimeout(() => {
      location.href = 'login.html'
    }, 2000)
  }
}